<?php

class xml
{
var $xml_array = array();
var $xml_attri = array();
var $db_array = array();
var $array_ok = null;
var $array_false = null;
var $array_false2 = null;


function auslesen()
{
 $i = 0;
 $test = simplexml_load_file('upload/strings_de.xml');
 foreach ($test->string as $value) {
    
   $this->xml_array[$i] = (string) $value;
   $this->xml_attri[$i] = (string) $value->attributes();
   
   $i++;
}//FOREACH END;
}// AUSLESEN END

function dbarray()
{
include_once 'config.php';
$conn = db();

$result = pg_query($conn, "SELECT string_name FROM catroid_typ");
if (!$result) {
  echo "An error occured.\n";
  exit;
}

$i = 0;
while ($row = pg_fetch_object($result)) {
    $this->db_array[$i] =  (string) $row->string_name;
	$i++;
}

}//dbarray ende

function marray()
{
   
   $this->array_false = array_diff($this->xml_attri, $this->db_array);
   $this->array_false2 = array_diff($this->db_array,$this->xml_attri);
   $this->array_ok = array_intersect($this->xml_attri, $this->db_array);
  

}

function newType()
{
  foreach($this->array_false as $value)
  {
	echo '<input type="checkbox" name="type[]" value="'.$value.'"> '.$value.' <br/>';
  }

}

function insertType($types)
{
include_once 'config.php';
$conn = db();

foreach($types as $value)
{
$res=pg_query($conn, "INSERT INTO catroid_typ (string_name,sortierung) VALUES ('$value', 1)"); 
}

}//end insert Type

function findWords($lang,$proj)
{
include_once 'config.php';
$conn = db();

$i = 0;
foreach($this->db_array as $value)
{

$key = array_search($this->db_array[$i], $this->xml_attri); 

$asso = $this->xml_attri[$i];
$result = pg_query_params($conn, 'SELECT id FROM catroid_typ WHERE string_name = $1', array($asso) );
//var_dump($result);
if (!$result) {
  //echo "An error occured.\n";
  exit;
}
$row =  pg_fetch_object($result);
$word =  $this->xml_array[$key];

$res=pg_query($conn, "INSERT INTO catroid_words (st_na_id,lang_id,user_id,name,likes,aktiv,project_id) VALUES ('$row->id','$lang',1, '$word',1,1,$proj)"); 
$i++;

}
}

function setArrays($attri, $xml)
{
$this->xml_array = $xml;
$this->xml_attri = $attri;
}

function ausgabe($lang)
{
include_once 'config.php';
$conn = db();
 $result = pg_query($conn, "SELECT id,string_name FROM catroid_typ");
if (!$result) {
  echo "An error occured.\n";
  exit;
}

$i = 0;
while ($row = pg_fetch_object($result)) {
    $result2 = pg_query($conn, "SELECT id FROM catroid_words WHERE st_na_id = '$row->id' AND lang_id = '$lang'");
	$rows = pg_num_rows($result2);
     if ($rows >= 1)
     {
	echo '<tr id="'.$row->id.'"><td>'.$row->string_name.'</td></tr>';
	 }
    
	//$i++;
}
}


}//CLASS END!

?>